<template>
  <div>
    <router-link to="./loginpage/loginemail">邮箱登录</router-link><br />
    <router-link to="./loginpage/register">注册账号</router-link><br />
    <el-button type="info" @click="gotoSeckill">秒杀页面</el-button><br />
    <router-link to="./adminpage/login">后台登录页面</router-link><br />
    <el-button type="info" @click="logout">退出登录</el-button><br />
  </div>
</template>
 
<script>
import router from "../router";
export default {
  methods: {
    //退出登录
    logout() {
      var storage = window.localStorage;
      storage.clear();
      this.$message({
        message: "用户已退出",
        type: "success",
      });
    },
    //登录秒杀页面
    gotoSeckill() {
      this.$axios
        .get("/seckill/gotoSeckillPage", {
          headers: {
            "x-access-token": localStorage.getItem("x-access-token"),
          },
        })
        .then((res) => {
       
          if (res.data.code == 200 && res.data.extend.result == "登陆成功") {
            router.push("./seckillpage/index");
          } else if (
            res.data.code == 401 &&
            res.data.extend.result == "用户不存在！"
          ) {
            this.$message.error("请先登录账号，才能参与秒杀活动");
          } else if (
            res.data.code == 401 &&
            res.data.extend.result == "token已过期，请重新登录"
          ) {
            this.$message.error("您已经很久没登录了，请重新登录");
          }
        });
    },
  },
};
</script>

<style>
</style>